package com.example.demomk.Fragment;

import android.view.View;

import androidx.fragment.app.Fragment;

import com.example.demomk.Interface.OnBottomBarListener;

public abstract class BaseFragment extends Fragment {
    protected void setHomeButtonListener(View.OnClickListener listener) {
        if (getActivity() instanceof OnBottomBarListener) {
            ((OnBottomBarListener) getActivity()).setHomeButtonListener(listener);
        }
    }

    protected void setPrintButtonListener(View.OnClickListener listener) {
        if (getActivity() instanceof OnBottomBarListener) {
            ((OnBottomBarListener) getActivity()).setPrintButtonListener(listener);
        }
    }

    // 其他按钮方法...

    @Override
    public void onDestroyView() {
        // 自动清除当前Fragment设置的监听
        if (getActivity() instanceof OnBottomBarListener) {
            ((OnBottomBarListener) getActivity()).clearAllListeners();
        }
        super.onDestroyView();
    }

    private boolean isFirstLoad = true;

    @Override
    public void onResume() {
        super.onResume();
        if (isFirstLoad) {
            isFirstLoad = false;
        } else {
            // 非首次加载时重新绑定监听器
            bindBottomBarListeners();
        }
    }
    // BaseFragment.java


    protected abstract void bindBottomBarListeners();
}